#pragma once

#define PAGE_SHIFT 12
#define PAGE_SIZE  ((unsigned long)1 << PAGE_SHIFT)

#ifdef __KERNEL__

#define PAGE_MASK        (~(PAGE_SIZE - 1))
#define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)

#define PTR_MASK         (~(sizeof(void *) - 1))

#define SIZEOF_PTR_LOG2  2

/* to find an entry in a page-table */
#define PAGE_DIR_OFFSET(base, address) \
    ((unsigned long *)((base) + ((unsigned long)(address) >> (PAGE_SHIFT - SIZEOF_PTR_LOG2) * 2 & PTR_MASK & ~PAGE_MASK)))

/* the no. of pointers that fit on a page */
#define PAGE_PTR(address) \
    ((unsigned long)(address) >> (PAGE_SHIFT - SIZEOF_PTR_LOG2) & PTR_MASK & ~PAGE_MASK)

#endif
